from flask import Flask,render_template
# from flask_bootstrap import Bootstrap

from exter import db
from models import User
# from config import Config



app = Flask(__name__)
# 数据库配置：
# Flask数据库的设置: app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://账号:密码@数据库ip地址:端口号/数据库名"
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:111@localhost:3306/fl'
# 动态追踪修改设置，如未设置只会提示警告, 不建议开启
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# 查询时会显示原始SQL语句
app.config['SQLALCHEMY_ECHO'] = True
app.secret_key = "sadfffsdf"

# app.config.from_object(Config)
# bootstrap = Bootstrap(app)
db.init_app(app)

# 创建Flask对象





# 防止出现RuntimeError: Working outside of application context.
# app.app_context().push()
with app.app_context():
    db.create_all()

@app.route('/')
def index():
    # 创建数据库表
    return {"111":"1111"}

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5001)
    print(1111)



# -*- coding: UTF-8 -*-
# from flask import Flask
# from flask_sqlalchemy import SQLAlchemy
#
# app = Flask(__name__)
# app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123@127.0.0.1:3306/111'
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# app.config['SQLALCHEMY_ECHO'] = True
#
# # 创建组件对象
# db = SQLAlchemy(app)
#
#
# # 构建模型类  类->表  类属性->字段  实例对象->记录
# class User(db.Model):
#     __tablename__ = 't_user'  # 设置表名, 表名默认为类名小写
#     id = db.Column(db.Integer, primary_key=True)  # 设置主键, 默认自增
#     name = db.Column('username', db.String(20), unique=True)  # 设置字段名 和 唯一约束
#     age = db.Column(db.Integer, default=10, index=True)  # 设置默认值约束 和 索引
#
#
# if __name__ == '__main__':
#     app.run(debug=True)
#     db.drop_all()
#     db.create_all()

